<?php
/**
* @file $Id: PreparePHP_SELF.fnc.php 437 2007-04-23 00:57:51Z focus-sis $
* @package Focus/SIS
* @copyright Copyright (C) 2006 Andrew Schmadeke. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.txt
* Focus/SIS is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.txt for copyright notices and details.
*/

function PreparePHP_SELF($tmp_REQUEST='',$exclude_vars='')
{
	if(!$tmp_REQUEST)
		$tmp_REQUEST = $_REQUEST;

	foreach($_COOKIE as $key=>$value)
		unset($tmp_REQUEST[$key]);

	if(is_array($exclude_vars))
	{
		foreach($exclude_vars as $var)
		{
			unset($tmp_REQUEST[$var]);
		}
	}

	if(is_array($tmp_REQUEST['cust']))
	{
		foreach($tmp_REQUEST['cust'] as $i=>$var)
		{
			if($var==='')
				unset($tmp_REQUEST['cust'][$i]);
		}
	}	

	if(is_array($tmp_REQUEST['cust_begin']))
	{
		foreach($tmp_REQUEST['cust_begin'] as $i=>$var)
		{
			if($var==='')
				unset($tmp_REQUEST['cust_begin'][$i]);
			if($tmp_REQUEST['cust_end'][$i]==='')
				unset($tmp_REQUEST['cust_end'][$i]);
		}
	}

	if(is_array($tmp_REQUEST['cust_log']))
	{
		foreach($tmp_REQUEST['cust_log'] as $o=>$var)
		{
			foreach($var as $i=>$v)
			{
				if($tmp_REQUEST['cust_log'][$o][$i]==='')
					unset($tmp_REQUEST['cust_log'][$o][$i]);
			}
		}
	}	


	if(is_array($tmp_REQUEST['year_cust_begin']))
	{
		foreach($tmp_REQUEST['year_cust_begin'] as $i=>$var)
		{
			if($var==='')
				unset($tmp_REQUEST['year_cust_begin'][$i]);
			if($tmp_REQUEST['year_cust_end'][$i]==='')
				unset($tmp_REQUEST['year_cust_end'][$i]);
			if($tmp_REQUEST['day_cust_begin'][$i]==='')
				unset($tmp_REQUEST['day_cust_begin'][$i]);
			if($tmp_REQUEST['day_cust_end'][$i]==='')
				unset($tmp_REQUEST['day_cust_end'][$i]);
			if($tmp_REQUEST['month_cust_begin'][$i]==='')
				unset($tmp_REQUEST['month_cust_begin'][$i]);
			if($tmp_REQUEST['month_cust_end'][$i]==='')
				unset($tmp_REQUEST['month_cust_end'][$i]);
		}
	}	

	if(is_array($tmp_REQUEST['year_cust_log']))
	{
		foreach($tmp_REQUEST['year_cust_log'] as $i=>$var)
		{
			if($var['LOG_DATE']['begin']==='')
				unset($tmp_REQUEST['year_cust_log'][$i]['LOG_DATE']['begin']);
			if($var['LOG_DATE']['end']==='')
				unset($tmp_REQUEST['year_cust_log'][$i]['LOG_DATE']['end']);
			if($tmp_REQUEST['month_cust_log'][$i]['LOG_DATE']['begin']==='')
				unset($tmp_REQUEST['month_cust_log'][$i]['LOG_DATE']['begin']);
			if($tmp_REQUEST['month_cust_log'][$i]['LOG_DATE']['end']==='')
				unset($tmp_REQUEST['month_cust_log'][$i]['LOG_DATE']['end']);
			if($tmp_REQUEST['day_cust_log'][$i]['LOG_DATE']['begin']==='')
				unset($tmp_REQUEST['day_cust_log'][$i]['LOG_DATE']['begin']);
			if($tmp_REQUEST['day_cust_log'][$i]['LOG_DATE']['end']==='')
				unset($tmp_REQUEST['day_cust_log'][$i]['LOG_DATE']['end']);
		}
	}
	
	$PHP_tmp_SELF = 'Modules.php?modname=' . $tmp_REQUEST['modname'];
	
	unset($tmp_REQUEST['modname']);
	
	if(count($tmp_REQUEST))
	{
		foreach($tmp_REQUEST as $key=>$value)
		{
			if(is_array($value))
			{
				foreach($value as $key1=>$value1)
				{
					if(is_array($value1))
					{
						foreach($value1 as $key2=>$value2)
						{	
							if(is_array($value2))
							{
								foreach($value2 as $key3=>$value3)
								{
									$PHP_tmp_SELF .= "&amp;".$key.'['.$key1.']['.$key2.']['.$key3.']='.urlencode(str_replace('\"','"',$value3));
								}
							}
							else
								$PHP_tmp_SELF .= "&amp;".$key.'['.$key1.']['.$key2.']='.urlencode(str_replace('\"','"',$value2));
						}
					}
					else
						$PHP_tmp_SELF .= "&amp;".$key.'['.$key1.']='.urlencode(str_replace('\"','"',$value1));
				}
			}
			else
			{
				if($tmp_REQUEST[$key] != '')
					$PHP_tmp_SELF .= "&amp;" . $key . "=" . urlencode(str_replace('\"','"',$value));
			}
		}
	}
	
	return $PHP_tmp_SELF;
}
?>